import requests,bs4
from urllib.request import quote

start = 0


while start < 1 :
    mvLink = 'https://movie.douban.com/top250'
    if start != 0:
        mvLink = mvLink + '?start='+str(start*25)+'&filter='
    mvPage = requests.get(mvLink)
    
    mvPageHtml = bs4.BeautifulSoup(mvPage.text,'html.parser')
    
    topNumDist = mvPageHtml.select('.article .grid_view li .pic em')
    topMvNameDist = mvPageHtml.select('.article .grid_view li .pic a img')
    topScoreDist = mvPageHtml.select('.article .grid_view li .info .bd .star .rating_num')
    topNumList = []
    topMvNameList = []
    topScoreList = []
    dowLinkList = []
    for top in topNumDist:
        topNumList.append(top.getText())
    for MvName in topMvNameDist:
        topMvNameList.append(MvName.get('alt'))
    for score in topScoreDist:
        topScoreList.append(score.getText())    
    
    #获取 下载链接列表
    for k in topMvNameList:
        gbkMvName = k.encode('gbk')
        searchMvLink = 'http://s.ygdy8.com/plus/so.php?typeid=1&keyword=' +quote(gbkMvName)
        
        showLinkPage = requests.get(searchMvLink)
        
        showLinkHtml = bs4.BeautifulSoup(showLinkPage.text,'html.parser')
        showLinkList = showLinkHtml.select('.co_content8 ul  b a')
        
        if len(showLinkList) < 1:
            dowLinkList.append('未找到')
            continue
        downPageUrl = 'http://s.ygdy8.com'+showLinkList[0].get('href')

        
        downPageContent = requests.get(downPageUrl).content.decode('gbk')
        downPageHtml = bs4.BeautifulSoup(downPageContent,'html.parser')
        downLinkDist = downPageHtml.select('table tbody tr a')
        
        if len(downLinkDist) < 1:
            dowLinkList.append('未找到')
            continue   
        dowLinkList.append(downLinkDist[0].get('href'))   
    for i in range(len(topMvNameList)):
        print('排名：'+str(topNumList[i])+' 电影名：'+str(topMvNameList[i])+' 评分：'+str(topScoreList[i])+' 下载链接：'+str(dowLinkList[i]))
        
    start = start + 1